package com.wan.activity;

import net.sourceforge.simcpux.Util;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.wan.commonsdk.Conet;
import com.wan.commonsdk.WanCommonSdk;

//------------------------------------------------------------------------
//
// 用户管理
//
//------------------------------------------------------------------------
public class usermanager extends BaseActivity implements View.OnClickListener {

    public static Activity activity = null;
    private Button mobile_bind,change_password,btn_close,btn_bind;
    private TextView tv_userid,manager_back_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (WanCommonSdk.screen_orientation == WanCommonSdk.SCREEN_ORIENTATION_PORTRAIT)
        {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        else
        {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
        super.onCreate(savedInstanceState);
        setContentView(Util.getResID("usermanager", "layout"));  
        activity                =   this;
        this.mobile_bind        =   (Button) findViewById( Util.getResID("mobile_bind", "id")); 
        mobile_bind.setOnClickListener(this);
        this.change_password    =   (Button)findViewById(Util.getResID("change_password", "id"));  
        change_password.setOnClickListener(this);
        manager_back_btn = (TextView) findViewById(Util.getResID("manager_back_btn", "id")); 
        manager_back_btn.setOnClickListener(this);
        this.btn_bind           =   (Button) findViewById(Util.getResID("btn_bind", "id")); 
        btn_bind.setOnClickListener(this);
        this.tv_userid          =   (TextView)findViewById(Util.getResID("tv_userid", "id")); 
        this.tv_userid.setOnClickListener(this);

        if (checkBind()){
            this.btn_bind.setVisibility(View.GONE);
            this.mobile_bind.setVisibility(View.GONE);
        }else{
            this.btn_bind.setText(Util.getResID("bind_false", "string"));   
            this.btn_bind.setBackgroundColor(Color.parseColor("#ff6646"));
        }

        String text = getUserid();
        if (text !=""){
            tv_userid.setText(text);
        }
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == Util.getResID("mobile_bind", "id")){   
            if (!checkBind()){
                Intent intent = new Intent(activity,mobilebindActive.class);
                activity.startActivity(intent);
                finish();
            }else{
                return;
            }
        }else if (v.getId() == Util.getResID("change_password", "id")){   
            Intent intent = new Intent(activity,changePassword.class);
            activity.startActivity(intent);
            finish();
        }else if (v.getId() == Util.getResID("manager_back_btn", "id")){  
            this.finish();
        }
    }

    private boolean checkBind(){  
        if(Conet.mUserInfo.getBind_Phone() !=null&&!"".equals(Conet.mUserInfo.getBind_Phone() )){
        	return true;
        }else{
        	return false;
        }
    }

    private String getUserid(){
    	if(Conet.mUserInfo.isGuest()){
    		return "当前帐号：游客（未注册）";
    	}else{
    		 return "当前帐号："+Conet.mUserInfo.getUser_name();
    	}
    }
}
